package com.heima.apis.article.fallback;

import com.heima.apis.article.IArticleClient;
import com.heima.model.article.dtos.ArticleDto;
import com.heima.model.common.dtos.ResponseResult;
import org.springframework.stereotype.Component;

import java.lang.reflect.InvocationTargetException;

@Component
public class IArticleClientFallback implements IArticleClient {
    @Override
    public ResponseResult saveArticle(ArticleDto dto) throws InvocationTargetException, IllegalAccessException {
        // 记录错误日志，便于问题排查
        System.err.println("文章微服务调用失败，触发降级处理机制。文章ID：" + (dto != null ? dto.getId() : "未知"));
        return ResponseResult.errorResult(500,"文章微服务调用失败，触发降级处理机制");
    }

    @Override
    public ResponseResult collectArticle(Integer userId, Long articleId, Boolean isCollect) {
        System.err.println("文章收藏服务调用失败，触发降级处理机制。用户ID：" + userId + "，文章ID：" + articleId);
        return ResponseResult.errorResult(500, "文章收藏服务调用失败，触发降级处理机制");
    }

    @Override
    public ResponseResult isArticleCollected(Integer userId, Long articleId) {
        System.err.println("文章收藏服务调用失败，触发降级处理机制。用户ID：" + userId + "，文章ID：" + articleId);
        return ResponseResult.errorResult(500, "文章收藏服务调用失败，触发降级处理机制");

    }

    @Override
    public ResponseResult getUserCollections(Integer userId, Integer page, Integer size) {
        System.err.println("获取用户收藏文章列表服务调用失败，触发降级处理机制。用户ID：" + userId);
        return ResponseResult.errorResult(500, "获取用户收藏文章列表服务调用失败，触发降级处理机制");
    }

    @Override
    public ResponseResult likeArticle(Integer userId, Long articleId, Boolean isLike) {

        System.err.println("文章点赞服务调用失败，触发降级处理机制。用户ID：" + userId + "，文章ID：" + articleId);
        return ResponseResult.errorResult(500, "文章点赞服务调用失败，触发降级处理机制");

    }

    @Override
    public ResponseResult isArticleLiked(Integer userId, Long articleId) {
        System.err.println("文章点赞服务调用失败，触发降级处理机制。用户ID：" + userId + "，文章ID：" + articleId);
        return ResponseResult.errorResult(500, "文章点赞服务调用失败，触发降级处理机制");

    }

    @Override
    public ResponseResult getUserLikedArticles(Integer userId, Integer page, Integer size) {
        System.err.println("获取用户点赞文章列表服务调用失败，触发降级处理机制。用户ID：" + userId);
        return ResponseResult.errorResult(500, "获取用户点赞文章列表服务调用失败，触发降级处理机制");

    }
}